package com.webchat.admin.controller.sys;


import com.webchat.admin.service.sys.SysDataDictionaryCategoryService;
import com.webchat.common.bean.APIPageResponseBean;
import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.common.config.annotation.ValidatePermission;
import com.webchat.common.helper.SessionHelper;
import com.webchat.domain.vo.request.sys.SysDataDictionaryCategoryRequestVO;
import com.webchat.domain.vo.response.sys.SysDataDictionaryCategoryBaseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 数据字典分类控制器
 *
 * @author SongRenShuo
 * @date 2025/06/28
 */
@RestController
@RequestMapping("/admin-service/sys/data-dictionary/category")
public class SysDataDictionaryCategoryController {

    @Autowired
    private SysDataDictionaryCategoryService sysDataDictionaryCategoryService;


    /**
     * 创建或者更新数据字典分类
     *
     * @param requestVO 请求 VO
     * @return {@link APIResponseBean }<{@link Long }>
     */
    @ValidatePermission
    @PostMapping("/save")
    public APIResponseBean<Long> save(@RequestBody SysDataDictionaryCategoryRequestVO requestVO) {

        String userId = SessionHelper.getCurrentUserId();
        requestVO.setOperator(userId);
        Long id = sysDataDictionaryCategoryService.save(requestVO);
        return APIResponseBeanUtil.success(id);
    }

    /**
     * 删除数据字典分类
     *
     * @param categoryId 分类 ID
     * @return {@link APIResponseBean }<{@link Long }>
     */
    @ValidatePermission
    @PostMapping("/delete/{categoryId}")
    APIResponseBean<Long> delete(@PathVariable Long categoryId) {

        String userId = SessionHelper.getCurrentUserId();
        boolean res = sysDataDictionaryCategoryService.delete(categoryId, userId);
        return APIResponseBeanUtil.success(res);
    }


    /**
     * 分页查询数据字典分类
     *
     * @param code     编号
     * @param name     名称
     * @param pageNo   页码
     * @param pageSize 每页条数
     * @return {@link APIPageResponseBean }<{@link SysDataDictionaryCategoryBaseVO }>
     */
    @ValidatePermission
    @GetMapping("/page")
    public APIPageResponseBean<SysDataDictionaryCategoryBaseVO> page(@RequestParam(value = "code", required = false) String code,
                                                                     @RequestParam(value = "name", required = false) String name,
                                                                     @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                                                     @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {

        return sysDataDictionaryCategoryService.page(code, name, pageNo, pageSize);
    }

    /**
     * 公告接口 - 数据字典分类
     *
     * @return {@link APIResponseBean }<{@link List }<{@link SysDataDictionaryCategoryBaseVO }>>
     */
    @ValidatePermission
    @GetMapping("/list")
    public APIResponseBean<List<SysDataDictionaryCategoryBaseVO>> list() {

        return sysDataDictionaryCategoryService.list();
    }


}
